package main.com.hu.spring5.testDemo;

import main.com.hu.spring5.Employee;
import main.com.hu.spring5.Password;
import main.com.hu.spring5.config.SpringConfig;
import main.com.hu.spring5.service.UserService;
import main.com.hu.spring5.factoryBean.MyBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpring5 {

    @Test
    public void testAdd1(){
        // 1. 加载Spring配置文件
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.txt");
        // 2. 获取配置的对象
        UserService userService = context.getBean("userService", UserService.class);

        System.out.println(userService);
        userService.add();
    }
    @Test
    public void testAdd2(){
        // 1. 加载Spring配置类
        ApplicationContext context =
                new AnnotationConfigApplicationContext(SpringConfig.class);
        // 2. 获取配置的对象
        UserService userService = context.getBean("userService", UserService.class);

        System.out.println(userService);
        userService.add();
    }

    @Test
    public void testEmployee(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.txt");
        Employee employee = context.getBean("employee", Employee.class);

        employee.out();
    }

    @Test
    public void testPassword(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean2.txt");
        Password password = context.getBean("password", Password.class);
        password.out();
    }

    @Test
    public void test3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean3.txt");
        MyBean employee = context.getBean("mybean", MyBean.class);
        System.out.println(employee);
    }
}
